<template>
  <yd-radio-group v-model="radio" color="#2e71c9" class="radio" v-if="list.length">
    <yd-radio :val="val.value" v-for="(val, key) in list" :key="key">{{val.name}}</yd-radio>
  </yd-radio-group>
</template>
<script>
  export default {
    name: 'xf-radio',
    props: {
      value: {type: null, default: ''},
      list: {type: Array, default: () => []},
      // 是否为必填，required为错误提示
      required: {type: String, default: ''}
    },
    computed: {
      radio: {
        get() {
          return this.value
        },
        set(val) {
          this.$emit('input', val)
        }
      }
    },
    methods: {
      validValue() {
        if (this.required && !this.radio) {
          this.$message.toast(this.required)
          return new Error(this.required)
        } else {
          return true
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../common/style/variable";
  .radio{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
</style>
